package com.tywj.lib.core.common.util

import android.text.InputFilter
import android.widget.EditText

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : EditText工具类
 *     version: 1.0
 * </pre>
 */

object EditTextUtil {

    /**
     * 为EditText增加一个额外的InputFilter
     * @param editText
     * @param filter
     */
    fun addFilter(editText: EditText, filter: InputFilter) {
        var oriFilters = editText.filters
        if (oriFilters==null) {
            oriFilters = arrayOfNulls(0)
        }
        val result = arrayOfNulls<InputFilter>(oriFilters.size + 1)
        System.arraycopy(oriFilters, 0, result, 0, oriFilters.size)
        result[oriFilters.size] = filter
        editText.filters = result
    }

}
